﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using FrameWork.web.Code;
using FrameWork.Entity;
using FrameWork.Components;
namespace FrameWork.web.Module.ITMS.FrontPage
{
    public partial class ModifyPassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                sys_UserTable ut = BusinessFacade.sys_UserDisp(Common.Get_UserID);
                this.labUser.Text = ut.U_CName;
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            //判断有没有输入新密码
            string strMeg = "";
            if (this.txtNewPwd.Text.Trim() == "")
            {
                strMeg += "请输入新密码！\\n";
            }
            if (this.txtNewPwd2.Text.Trim() == "")
            {
                strMeg += "请输入重新输入新密码！\\n";
            }
            if (strMeg == "")
            {
                if (this.txtNewPwd.Text.Trim() != this.txtNewPwd2.Text.Trim())
                {
                    strMeg += "新密码输入不一致！\\n";
                }
            }
            if (strMeg != "")
            {
                this.ClientScript.RegisterClientScriptBlock (this.GetType(), "Meg", "<script>alert('" + strMeg + "');</script>");
                return;
            }
            string strOldPwd = Common.md5(this.txtOldPwd.Text.Trim(), 32);
            string strNewPwd = Common.md5(this.txtNewPwd.Text.Trim(), 32);
            sys_User userOld = new sys_User();
            userOld.UserID = Common.Get_UserID;
            userOld.U_Password = strOldPwd;
            sys_User userNew = new sys_User();
            userNew.U_Password = strNewPwd;

            sys_UserCs userCs = new sys_UserCs();
            strMeg = userCs.UserChangePWD(userOld, userNew);
            this.ClientScript.RegisterClientScriptBlock(this.GetType(), "Meg", "<script>alert('" + strMeg + "');</script>");
            if (strMeg == "修改成功！")
            {
                this.txtNewPwd.Text = "";
                this.txtNewPwd2.Text = "";
                this.txtOldPwd.Text = "";
            }
        }
    }
}
